﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Kimd.Logic
{
    public class SignalBase
    {
        private bool _status = false;
        private bool _isBreak = false;
        private bool _isAutoReset = false;
        public bool IsForceBreak = false;
        public SignalBase(bool status, bool isAutoReset)
        {
            _status = status;
            _isAutoReset = isAutoReset;
        }

        public bool Wait()
        {
            while(!_status && !_isBreak && !IsForceBreak)
            {
                System.Threading.Thread.Sleep(20);
            }
            if (IsForceBreak)
                IsForceBreak = false;
            if (_isBreak)
                return false;
            if(_status && _isAutoReset)
                Reset();
            return true;
        }
        public bool GetStatus()
        { 
            return _status; 
        }
        public void Set()
        {
            _status = true;
        }
        public void Reset()
        {
            _status = false;
        }
        public void Break()
        {
            _isBreak = true;
        }
        public void ResetBreak()
        {
            _isBreak = false;
        }
    }
}
